package com.ruoyi.project.jiaqin.memberquotationclass.service.impl;

import java.util.List;

import com.ruoyi.project.jiaqin.thrclasstrend.service.IThrClassTrendService;
import com.ruoyi.project.jiaqin.twoclasstrend.service.ITwoClassTrendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.jiaqin.memberquotationclass.mapper.MemberQuoteClassMapper;
import com.ruoyi.project.jiaqin.memberquotationclass.domain.MemberQuoteClass;
import com.ruoyi.project.jiaqin.memberquotationclass.service.IMemberQuoteClassService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 用户关注分类Service业务层处理
 *
 * @author admin
 * @date 2021-01-09
 */
@Service
public class MemberQuoteClassServiceImpl implements IMemberQuoteClassService
{
    @Autowired
    private MemberQuoteClassMapper memberQuoteClassMapper;
    @Autowired
    private ITwoClassTrendService iTwoClassTrendService;
    @Autowired
    private IThrClassTrendService iThrClassTrendService;

    /**
     * 查询用户关注分类
     *
     * @param memberId 用户关注分类ID
     * @return 用户关注分类
     */
    @Override
    public MemberQuoteClass selectMemberQuoteClassById(String memberId)
    {
        return memberQuoteClassMapper.selectMemberQuoteClassById(memberId);
    }

    /**
     * 查询用户关注分类列表
     *
     * @param memberQuoteClass 用户关注分类
     * @return 用户关注分类
     */
    @Override
    public List<MemberQuoteClass> selectMemberQuoteClassList(MemberQuoteClass memberQuoteClass)
    {
        List<MemberQuoteClass> list = memberQuoteClassMapper.selectMemberQuoteClassList(memberQuoteClass);
        if(list != null && list.size() !=0){
            for (MemberQuoteClass mqc: list) {
                if(mqc.getClassLevel() == 1){
                    //二级分类查涨跌幅
                    Integer twoStatus = iTwoClassTrendService.selectNowStatusByTwoClassId(mqc.getQuotatonClassId());
                    mqc.setClassStatus(twoStatus);
                }
                if(mqc.getClassLevel() == 2){
                    //三级分类查涨跌幅
                    Integer thrStatus = iThrClassTrendService.selectNowStatusByThrClassId(mqc.getQuotatonClassId());
                    mqc.setClassStatus(thrStatus);
                }
            }
        }
        return list;
    }

    /**
     * 新增用户关注分类
     *
     * @param memberQuoteClass 用户关注分类
     * @return 结果
     */
    @Override
    public int insertMemberQuoteClass(MemberQuoteClass memberQuoteClass)
    {
        return memberQuoteClassMapper.insertMemberQuoteClass(memberQuoteClass);
    }

    /**
     * 修改用户关注分类
     *
     * @param memberQuoteClass 用户关注分类
     * @return 结果
     */
    @Override
    public int updateMemberQuoteClass(MemberQuoteClass memberQuoteClass)
    {
        return memberQuoteClassMapper.updateMemberQuoteClass(memberQuoteClass);
    }

    /**
     * 删除用户关注分类对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMemberQuoteClassByIds(String ids)
    {
        return memberQuoteClassMapper.deleteMemberQuoteClassByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除用户关注分类信息
     *
     * @param memberId 用户关注分类ID
     * @return 结果
     */
    @Override
    public int deleteMemberQuoteClassById(String memberId,String quotatonClassId)
    {
        return memberQuoteClassMapper.deleteMemberQuoteClassById(memberId,quotatonClassId);
    }
}
